package cn.itsource.service.impl;

import cn.itsource.domain.Teacher;
import cn.itsource.mapper.TeacherMapper;
import cn.itsource.query.TeacherQuery;
import cn.itsource.service.ITeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
//事务传播机制 - SUPPORTS支持、在调用多个方法调用的时候使用
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
@Slf4j
public class TeacherServiceImpl implements ITeacherService {


    //一个业务中查询的功能要多一些的 //若伊框架
    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public List<Teacher> findAll() {
        return teacherMapper.findAll();
    }

    @Override
    public Teacher findOne(Integer id) {
        return teacherMapper.findOne(id);
    }

    @Transactional //Propagation.REQUIRE + readOnly() default false
    @Override
    public void delete(Integer id) {
        teacherMapper.delete(id);
    }

    @Transactional
    @Override
    public void add(Teacher teacher) {
        teacherMapper.add(teacher);
    }


    @Transactional
    @Override
    public void update(Teacher teacher) {
        teacherMapper.update(teacher);
    }

    @Override
    public Map<String, Object> queryPage(TeacherQuery teacherQuery) {
        Map<String, Object> map = new HashMap<>();
        map.put("totals",teacherMapper.getCount(teacherQuery));
        map.put("data",teacherMapper.getData(teacherQuery));
        return map;
    }

    @Transactional
    @Override
    public void patchDel(Integer[] ids) {
        teacherMapper.patchDel(ids);
    }

}
